<?php

namespace app\admin\controller;
use app\base\controller\Base;
use think\Request;
use think\Cache;
use think\Config;
use think\Session;



class Information extends Base
{
    public  $model;

    public function __construct()
    {
   $this->model = model("Information");
        parent::__construct();

    }

    /**
     * @return \think\response\Json  询价历史
     */
    public function index()
    {//
     $where = [];
     $res = $this->model->Information_page($where);
     return   resJson(1,$this->ecLang("query"),$res['res'],$res['pageInfo']);
    }


    //保存用户信息
    public function save(){
        $data = [];
        if(isset($this->image)){
            $tdata =  saveBase64Image($this->image);
            if($tdata['code']==1)
            {
                $data['image'] = $tdata['url'];
            }
        }
        $data['title'] = $this->title;
        $data['content'] = $this->content;
        $res = $this->model->save($data);
        if(!$res)
        {
            return    failJson("添加失败");
        }
        return    sucessJson("添加成功");
    }
    /**
     *   排序
     */
    public function disorder(){
        $data = delwithData($this);
        if(empty($data))
        {
            return    failJson("数据不能为空");
        }
        $res = $this->model->save($data,['id'=>$this->id]);
        if(!$res)
        {
            return    failJson("添加失败");
        }
        return    sucessJson("添加成功");
    }


    public function updateit(){

        $data = [];
        if(isset($this->image)){
            $tdata =  saveBase64Image($this->image);

            if($tdata['code']==1){
                $data['image'] = $tdata['url'];
            }
        }
        $data['title'] = $this->title;
        $data['content'] = htmlspecialchars($this->content);
        $res = $this->model->save($data,['id'=>$this->id]);
        if(!$res)
        {
            return     failJson("更新失败");

        }
        return  sucessJson("更新成功");
    }




    public function del(){
        $res =   $this->model->delete(['id'=>$this->id]);
        if(!$res)
        {
            return    failJson("删除失败");

        }
        return     sucessJson("删除成功");
    }




}
